<template>
    <div>
        <div class="book_title">
            <h1 align="center">图书录入</h1>
        </div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统中心</el-breadcrumb-item>
            <el-breadcrumb-item>录入图书</el-breadcrumb-item>
        </el-breadcrumb>
        <hr>
        <br>
            <el-form :model="bookSingle" ref="bookForm" label-width="80px">
                <el-form-item label="RFID" prop="rfid">
                    <el-input v-model="bookSingle.rfid"></el-input>
                </el-form-item>
                <el-form-item label="条形码" prop="qrCode">
                    <el-input v-model="bookSingle.qrCode"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="entryBookSingle">确 定</el-button>
                    <el-button type="info" @click="clearFrom">取 消</el-button>
                </el-form-item>
            </el-form>

    </div>
</template>

<script>
    export default {
        name: "entryBookSingle",
        data(){
            return{
                bookSingle:{
                    replenishmentTaskCode:"",
                    rfid:'',
                    qrCode:'',
                    bookDetailedCode:''
                }
            }
        },
        methods:{
            entryBookSingle:function () {
              this.$refs['bookForm'].validate((valid)=>{
                if(!valid){
                  return
                }
                //JSON.parse() 字符串转对象，JSON.stringify对象转字符串
                var staffMember = JSON.parse(window.sessionStorage.getItem('tbStaffMember'))
                var id=staffMember.id;
                this.$http.post('entryBookSingle?rfid='+this.bookSingle.rfid+'&qrCode='+this.bookSingle.qrCode+'&bookDetailedCode='+this.bookDetailedCode+'&id='+id).then((res)=>{
                  if(res.data.success){
                    this.$message.success(res.data.message)
                  }else {
                    this.$message.error(res.data.message)
                  }
                })
              })
              let staffMember=JSON.parse(sessionStorage.getItem("tbStaffMember"));//JSON.parse() 字符串转对象，JSON.stringify对象转字符串
              var staffMemberCode=staffMember.code;
              this.$http.post('generateReplenishmentRecord?replenishmentTaskCode='+this.replenishmentTaskCode+'&staffMemberCode='+staffMemberCode).then((res)=>{
                if(res.data.success){
                    this.$message.success(res.data.message)
                    this.$router.push("/getReplenishmentRecord");
                }else {
                    this.$message.error(res.data.message)
                }
              })
            },

            clearFrom:function () {
                this.$refs['bookForm'].resetFields();
            }
        },
        mounted(){
            this.replenishmentTaskCode=this.$route.params.id;
            this.bookDetailedCode=this.$route.params.bookDetailedCode;
        }

    }
</script>

<style lang="less" scoped>
    .book_title{
        color: black;
    }
</style>
